package com.lanou.sinasports.activity;


import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.GridView;
import android.widget.ImageView;

import com.android.volley.Response;
import com.android.volley.VolleyError;

import com.lanou.sinasports.R;
import com.lanou.sinasports.adapter.GridViewAdapter;
import com.lanou.sinasports.beans.GsonGrid;
import com.lanou.sinasports.utils.DragGridView;
import com.lanou.sinasports.utils.GsonRequest;
import com.lanou.sinasports.utils.LessonApplication;
import com.lanou.sinasports.utils.VolleySingleton;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by dllo on 16/1/16.
 */
public class DropDownActivity extends AppCompatActivity {
    private ImageView imageView;
    private String url="http://client.mix.sina.com.cn/startrek/api/cfg/get/?client_deviceid=606f8e0559ca33cfa214e8e14c061c40";
    private VolleySingleton queue;
    private GridViewAdapter adapter;
    private DragGridView gridView;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_dropdown);
        imageView= (ImageView) findViewById(R.id.iv_drop_down_cancel);
        gridView= (DragGridView) findViewById(R.id.gv_drop);
        imageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

        queue=VolleySingleton.getInstance();
        final List<String> data=new ArrayList<>();

        GsonRequest<GsonGrid> request=new GsonRequest<GsonGrid>(url, GsonGrid.class, new Response.Listener<GsonGrid>() {
            @Override
            public void onResponse(GsonGrid gsonGrid) {
                int size=gsonGrid.getResult().getData().getInte().getNews().size();
                for(int i=0;i<size;i++){
                    String title=gsonGrid.getResult().getData().getInte().getNews().get(i).getTitle();
                    data.add(title);
                    Log.d("DropDownActivity", title);
                }
                adapter=new GridViewAdapter(LessonApplication.getContext(),data);
                gridView.setAdapter(adapter);
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {

            }
        });
        queue._addRequest(request);
    }
}
